﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/05/10
 * 
 * 功能说明：操作配置
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Whir_System_Module_Log_OperateLog : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();

        if (!IsPostBack)
        {
            BindData();
        }
    }

    //绑定
    protected void BindData()
    {
        string searchUser = txtOperateUser.Text.Trim();
        string operateType = ddlOperateType.SelectedItem.Value;
        string where = "1=1";
        if (!string.IsNullOrEmpty(searchUser))
        {
            searchUser = Whir.SQLServerDAL.DbHelperSQL.GetSingle("select adminID from Whir_AdminInfo where adminName = '" + searchUser + "'").ToString();
            if (!string.IsNullOrEmpty(searchUser))
            {
                where += " AND [operateUserID] = " + searchUser;
            }
        }
        if (operateType != "-1")
        {
            where += " AND [Title] like '%" + operateType + "%' AND operateDesc like '%" + operateType + "%'";
        }

        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.GetList("Whir_OperateLog", "createDate", "*,(select adminName from Whir_AdminInfo where adminID=operateUserID) operateUser", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex - 1, where, "", "createDate desc");
        int rowCount = int.Parse(ds.Tables[1].Rows[0][0].ToString());
        AspNetPager1.RecordCount = rowCount;
        if (rowCount > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
            divMessage.Visible = false;
        }
        else
        {
            GridView1.Controls.Clear();
            divMessage.Visible = true;
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }

    //删除
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int[] cbs = this.GridView1.CheckedIndexs;

        if (cbs.Length == 0)
        {
            Whir.Common.WebHelper.JsHelper.Alert(Page, "请选择记录!");
            return;
        }

        Whir.Log.SQLServerDAL.Whir_OperateLog bll = new Whir.Log.SQLServerDAL.Whir_OperateLog();
        foreach (int cb in cbs)
        {
            bll.Delete(cb);
        }

        BindData();

        Whir.Common.WebHelper.JsHelper.Alert(Page, "删除成功!");
    }

    //类型
    protected string getType(string str)
    {
        string s = "";
        switch (str)
        {
            case "1":
                s = "添加";
                break;
            case "2":
                s = "修改";
                break;
            case "3":
                s = "删除";
                break;
            case "4":
                s = "登录";
                break;
            case "5":
                s = "非法访问";
                break;
            case "6":
                s = "退出";
                break;
            default:
                s = "其它";
                break;
        }

        return s;
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }
}
